#pragma once

#include <iostream>
#include <pthread.h>
#include <semaphore.h>

const unsigned int gvalue = 1;

namespace SemMoudule
{
    class Sem
    {
    public:
        Sem(unsigned int value = gvalue)
        :_val(value)
        {
            int n = sem_init(&_sem, 0, _val);
            (void)n;
        }

        void P()
        {
            int n = sem_wait(&_sem);
            (void)n;
        }

        void V()
        {
            int n = sem_post(&_sem);
            (void)n;
        }

        ~Sem()
        {
            int n = sem_destroy(&_sem);
            (void)n;
        }

    private:
        sem_t _sem;
        unsigned int _val;
    };
}